package com.swn.common.util;

public class MoneyUtil {
	/**-人民币 大写转换
     * 
     * @param num ----要转化的数字 
     * @return
     */
    public static String makeUpperCaseSum(String numStr) {
		String isNeg = "";//正或者负
		double num = Double.parseDouble(numStr);
		    if (num < 0) {
		        num *= -1;
		        isNeg = "负";
		        numStr = numStr.substring(1);
		    }
		    final String[] upper_number = { "零","壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
		    final String[] number_dw = { "", "拾", "佰", "仟", "万", "拾", "佰",
		            "仟", "亿", "拾", "佰", "仟", "万" };
		    String operate = numStr;
		    String upper_str = "";
		    String upper_str_pre = "";
		    String upper_str_later = "";
		    String vsDx;
		    int i, j, point_pos, int_len;
		    if (num < 0.01) {
		        return "零圆整";
		    }
		
		    upper_str_pre = "";
		
		
		    point_pos = operate.indexOf(".");
		    if (point_pos == -1)
		        int_len = operate.length();
		     else 
		        int_len = point_pos;
		    if (int_len > number_dw.length) 
		        return "too long ！！！";
		    if (num > 0) {
		        for (i = 0; i < operate.length(); i++) {
		            j = int_len - i;
		            if(j>0){//整数部分
		                int k = Integer.parseInt(operate.substring(i, i + 1));
		                if(k==0){//数字为0时
		                if(j==5||j==9)//单位为亿或者万时
		                    upper_str_pre += upper_number[k] + number_dw[j-1]; 
		                    else               
		                upper_str_pre +=  upper_number[k];
		                }
		                else
		                upper_str_pre += upper_number[k] + number_dw[j-1];           
		            }else if(j<0){//小数部分
		                int k = Integer.parseInt(operate.substring(i, i + 1));
		                upper_str_later += upper_number[k]; 
		                if(j==-1)
		                    upper_str_later += "角";
		                else
		                    upper_str_later += "分";
		            }
		        } //end for           
		    } //end if
		upper_str_pre += "圆";
		    while(upper_str_pre.indexOf("零零")!=-1){
		    upper_str_pre = upper_str_pre.replaceAll("零零","零");
		    }
		upper_str_pre = upper_str_pre.replaceAll("零万","万");
		upper_str_pre = upper_str_pre.replaceAll("零亿","亿");
		upper_str_pre = upper_str_pre.replaceAll("亿万","亿零");
		upper_str_pre = upper_str_pre.replaceAll("零零","零");
		upper_str_pre = upper_str_pre.replaceAll("零圆","圆");
		if("圆".equals(upper_str_pre))
		upper_str_pre = "";
		upper_str = isNeg+upper_str_pre + upper_str_later;
		upper_str = upper_str.replaceAll("零角零分","整");
		if(point_pos == -1)
		upper_str += "整";
		    return upper_str;
    }
    
    public static void main(String[] args) {
		System.out.println(makeUpperCaseSum("1234567890.127"));
	}
}
